﻿using System;
using System.Text;
using AccelerateSensor.SocketServer.Tools;

namespace AccelerateSensor.SocketServer.Handler
{
    public static class MessageHelper
    {
        private static byte[] _heartbeatLenBuffer;
        private static byte[] _heartbeatBuffer;

        public static byte[] GetHeartbeatLenBuffer()
        {
            if (_heartbeatLenBuffer == null)
            {
                _heartbeatLenBuffer = BitConverter.GetBytes(Constants.HeartbeatString.Length);
                Array.Reverse(_heartbeatLenBuffer);
            }

            return _heartbeatLenBuffer;
        }

        public static byte[] GetHeartbeatBuffer()
        {
            return _heartbeatBuffer ?? (_heartbeatBuffer = Encoding.UTF8.GetBytes(Constants.HeartbeatString));
        }
    }
}
